<%-- 
    Document   : edit_controller
    Created on : 2009-5-24, 4:12:14
    Author     : user
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page language="java" import="java.sql.*, java.io.*, java.util.*, database.*" %>
<%@ page import="creater.*" %>
<jsp:useBean id="con" class="database.DatabaseConnection"/>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <%
        con.createConnection();
        String title = null;
        String content = null;
        String address = null;
        String newsType = null;
        int ID = new Integer(session.getAttribute("ID").toString()).intValue();

        ResultSet rs = con.getNews(ID);

                if (!(request.getParameter("title").toString().isEmpty())) {
            System.out.println("sdsadasdasdsadasd");
            title = request.getParameter("title");
        }
        if (!(request.getParameter("content").toString().isEmpty())) {
            content = request.getParameter("content");
        }

        if (rs.next()) {
            address = rs.getString("Address");
            newsType = rs.getString("Type");
        }


        if (title != null) {
            if (content != null) {
                String rootPath = request.getRealPath("/");

                String[] temp = address.split("/");

                address = temp[1];
                for (int j = 2; j < temp.length; j++) {
                    //System.out.println(temp[j]);
                    address = address + "\\" + temp[j];
                }
                //System.out.println(address);
                //System.out.println("sdsd"+title + content);
                newsCreater.insert(title, content, rootPath + address, rootPath);

                con.insertNews(title, ID);

        %>

        <%=title%><br>
        <%=content%><br><br>
        It is allready store at <%=address%>
        <input align="center" type="button" value="back" onclick="window.history.back()">
        <%

            } else {
                out.println("<center>Please enter a correct content<br>");
                out.println("<input align=\"center\" type=\"button\" value=\"back\" onclick=\"window.history.back()\"></center>");
            }

        } else {
            out.println("<center>Please enter correct title<br>");
            out.println("<input align=\"center\" type=\"button\" value=\"back\" onclick=\"window.history.back()\"></center>");
        }
        %>
    </body>
</html>